
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>学并思-留言板</title>

    <!-- Bootstrap core CSS -->
    <link href="./Tpl/css/bootstrap.min.css" rel="stylesheet">
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <form class="navbar-form navbar-right">
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">登录</button>
          </form>
        </div>
      </div>
    </nav>

    <!-- Main jumbotron for a primary marketing message or call to action -->


    <div class="container" style="padding-top:80px;">
      <!-- Example row of columns -->
      <div class="row">
		<!-- 循环数据库中的留言信息 -->
      	<style type="text/css">
            .info{
                float:left;
                line-height: 30px;
            }
            .glyphicon-ok{
                color: green;
            }
            .glyphicon-remove{
                color: red;
            }

        </style>
        <form id="regform" method="post" action="./addUser.php" class="form-horizontal">
            <div class="form-group">
              <label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
              <div class="col-sm-3">
                <input type="text"  name="username" class="form-control" >
              </div>
               <p class="info" ></p>
            </div>
            <div class="form-group">
              <label for="inputEmail3" class="col-sm-2 control-label">邮箱</label>
              <div class="col-sm-3">
                <input type="text" name="email" class="form-control" >

              </div>
              <p class="info" ></p>
            </div>
            <div class="form-group">
              <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
              <div class="col-sm-3">
                <input type="password" name="password" class="form-control" >
              </div>
              <p class="info" ></p>
            </div>
            <div class="form-group">
              <label for="inputPassword3" class="col-sm-2 control-label">确认密码</label>
              <div class="col-sm-3">
                <input type="password" name="repassword" class="form-control" >
              </div>
              <p class="info" ></p>
            </div>
            <div class="form-group">
              <div class="col-sm-offset-2 col-sm-3">
                <p id="regbtn" class="btn btn-primary">注册</p>
              </div>
            </div>
          </form>

      </div>

      <hr>

      <footer>
        <p>&copy; 2016 Company, Inc.</p>
      </footer>
    </div> 
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript">
        $(function  () {
            $('input').blur(function(event) {
                data = $(this).val();
                name = $(this).attr('name');
                obj = $(this);

                if(name=="repassword"){
                  if(data!=$('input[name="password"]').val()){
                    obj.parent().siblings('.info').html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>两次密码不一致');
                  }else{
                      obj.parent().siblings('.info').html('<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>');
                  }
                  return;
                }
                str = name+"="+data;
                $.ajax({
                  url: './regCheck.php',
                  type: 'post',
                  dataType: 'json',
                  data:str
                })
                .done(function(res) {
                    if(res.error==1){
                      obj.parent().siblings('.info').html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>'+res.info);
                    }else{
                      obj.parent().siblings('.info').html('<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>');
                    }
                })
                .fail(function() {
                    // alert("删除失败，通讯不成功");
                })
                

            });

            $('#regbtn').click(function(event) {
                  
                for (var i = 0; i <$('p.info').length; i++) {
                    res = $('p.info').eq(i).find('.glyphicon-ok');
                    if(res.length==0){
                        alert("数据还不完整，不能注册");

                        return;
                    };
                };
                $('#regform').submit();
            });
        })
    </script>
  </body>
</html>
